/**
 * 
 */
package niuke.练习赛15;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

/**
 * @author zhong
 * 
 */
public class 沃老师学生的成绩 {

	static class StudentScore implements Comparable<StudentScore> {
		String name;
		String score;
		String printScore;

		@Override
		public int compareTo(StudentScore o) {// O（len）
			int cmpScore = this.score.compareTo(o.score);
			if (cmpScore != 0) {
				return -cmpScore;
			}
			return this.name.compareTo(o.name);
		}

		public StudentScore(String name, String score) {
			this.name = name;
			// 去除分数尾部的0
			this.printScore = score;
			int i = score.length() - 1;
			while (i > 0 && score.charAt(i) == '0') {
				i--;
			}
			this.score = score.substring(2, i + 1);
		}
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		scanner.nextLine();
		ArrayList<ArrayList<StudentScore>> scores = new ArrayList<>();
		for (int i = 0; i < 10; i++) {
			scores.add(new ArrayList<StudentScore>());
		}

		for (int i = 0; i < n; i++) {
			String string = scanner.nextLine();
			String[] strings = string.split(" ");
			int start = strings[1].charAt(0) - '0';
			scores.get(start).add(new StudentScore(strings[0], strings[1]));
		}
		scanner.close();
		for (int i = 9; i >= 0; i--) {
			ArrayList<StudentScore> arrayList = scores.get(i);
			Collections.sort(arrayList);
			for (StudentScore studentScore : arrayList) {
				System.out.println(studentScore.name + " " + studentScore.printScore);
			}
		}
	}

}
